<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Index extends Controller
{
    //注册页面提交信息的方法
    public function index(){
        $phone=$_POST['username'];
        $password=$_POST['password'];
        $random=mt_rand('100000','999999');
        Db::execute('insert into zhuce (phone,passwd) values (?,?)',[$phone,$password]);
        Db::execute('insert into identify (identify) values (?)',[$random]);
       //$result=Db::query('select  * from zhuce where id=?', [8]);
      // dump($result);
      //   print_r($this->request->param());
      // 发送短信模块
      // $ch = curl_init();
      // $apikey = "018e6099b6ff17773722eee678a9dcb2";
      // $mobile = "15910587194"; //请用手机号代替
      // $text="【联创互动】您的验证码是".$random;
      // $data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
      // curl_setopt ($ch, CURLOPT_URL, 'http://sms.yunpian.com/v2/sms/single_send.json');
      // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
      // curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
      // $json_data = curl_exec($ch);
      // $array = json_decode($json_data,true);
      $this ->redirect('login',Null,302, '新增成功,页面跳转中...');
    }
    //加载登录的控制器的方法
    public function login() {
        return $this->fetch('login');
    }

    public function zhuce()
    {
        return $this->fetch('zhuce');
    }

    public function  loginadd(){
    $username=$_POST['username'];
    $pass=$_POST['password'];
    //var_dump($pass);exit;
    if($username){
       //$data=Db::table('zhuce')->where('phone',$username)->find();
        $data=Db::table('zhuce')->where('phone',$username)->find();
      //$result=Db::table('zhuce')->fetchsql('ture')->find();
     $password=$data['passwd'];
       if($pass == $password){
                 $this ->redirect('Shopinfo/index',Null,302, '新增成功,页面跳转中...');
        }else{
                    return   "你输入的密码不正确,请重新输入";
                    }
                    
            }else{
            return     "你的登录的账号不存在,请重新输入!";
        }
    }
    public function  verify(){
            $phone = $_POST['phone'];
            $data=Db::table('zhuce')->where('phone',$phone)->find();
            if($data){
                            return  json(['status'=>'200','msg'=>'']);
            }else{
                 return  json(['status'=>'500','msg'=>'手机号码不存在']);
            }
       
    }
 
}
